package api_servers
{
	public dynamic class api_externalserver extends api_server {
		public var vars:Object = null;
		public function api_externalserver(a_sroot:Object, api_url:String, viewer_id:String, app_id:String, secret:String, timerLimit:int=100) {
			super(a_sroot, api_url, viewer_id, app_id, secret, timerLimit);
		}
		
		public function convertVars(): Object {
			return {};
		}

	    override protected function prepareData(a_queryID:String, data:*):* {
	    	argConvert(data);
	    	return data;
	    }
	    
		override public function get flashVars(): Object {
			return vars;
		}
		
		protected function argConvert(data: Object): void {
			if (data is Array) 
				for (var ii: int; ii<data.length; ii++) argConvert(data[ii]);
			else {
				var _convertVars: Object = convertVars();
				for (var i: String in _convertVars) {
					if (data.hasOwnProperty(i)) {
						var val: Object = data[i];
						delete(data[i]);
						data[_convertVars[i].name] = (val != null)? 
							((_convertVars[i].cnv!=null)?(_convertVars[i].cnv(val)):val):val;
					}
				}
			}
		}
	}
}